package sparkExamples.exerciseDemo

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object ExerciseDemo03 {

  def main(args: Array[String]): Unit = {

    val conf = new SparkConf().setAppName("ExerciseDemo").setMaster("local[*]")
    val sparkContext = new SparkContext(conf)

    val txtRDD = sparkContext.textFile("src\\main\\scala\\data\\exerciseData.txt")

    /**
     * 8、13班有多少人参加考试？
     */

    val class13 = txtRDD.filter {
      line => {
        val strings = line.split(" ")
        if (strings(0) == "13") {
          true
        } else {
          false
        }
      }
    }
    val sum13 = class13.map {
      line => {
        val strings = line.split(" ")
        strings(1)
      }
    }.distinct().count()

    println("13班人数：" + sum13)

    sparkContext.stop()
  }

}
